package com.cgmnx.admin.model.enums.rbac;

import com.cgmnx.admin.common.enums.EnumTrait;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;


public enum OperationType implements EnumTrait {
    DEFAULT(1, "默认", 1),
    ROLE(2, "角色管理", 0),
    URL(3, "资源管理", 0),
    USER(4, "管理员管理", 0),
    ROLE_USER(5, "角色关联账号", 1),
    ROLE_URL(6, "角色关联权限", 1),
    APP_USER(7, "账号信息", 0),
    ENTERPRISE(8, "企业账户信息", 0),
    BIZ_INFO(9, "应用信息", 0),
    BIZ_USER(10, "应用账号", 0),
    MESSAGE(11, "消息中心", 0),
    LOGIN(12, "登录", 0),
    APP_COUNT(13, "账号账户", 1),
    ENTERPRISE_ACCOUNT(14, "企业账户", 1),;

    private int code;
    private String name;
    private int show;

    OperationType(int code, String name, int show) {
        this.code = code;
        this.name = name;
        this.show = show;
    }

    public static OperationType codeOf(int code) {

        for (OperationType operationType : OperationType.values()) {
            if (operationType.getCode() == code) {
                return operationType;
            }
        }
        return null;
    }

    public static List<Map<String, String>> getList() {

        List<Map<String, String>> list = Lists.newArrayList();

        for (OperationType type : OperationType.values()) {

            if (type.show == 0) {
                Map<String, String> map = Maps.newHashMap();
                map.put("code", String.valueOf(type.getCode()));
                map.put("name", type.getName());
                list.add(map);
            }

        }
        return list;
    }

    public int getCode() {
        return this.code;
    }

    public String getName() {
        return this.name;
    }
}
